查看原文
其他

learn R wisdom with fortunes

Y叔叔 YuLabSMU 2022-09-20

I like running fortune every time when the terminal was started. A screenshot is shown below:

wmaker

At the end of the post trick things in R, I introduced the fortunes package of R. The fortune program provides UNIX related quotations, while the quotations supplied by the R package, fortunes, are all R related. We can learn a lot from these quotations.

> fortune(343)
Sooner or later most R beginners are bitten by this all too convenient
shortcut. As an R newbie, think of R as your bank account: overuse of
$-extraction can lead to undesirable consequences. It's best to acquire the
'
[[' and '[' habit early.
  -- Peter Ehlers (about the use of $-extraction)
     R-help (March 2013)

I have answered why '[[' and '[' is better than '$' in the post on tricky things in R.

One more thing I want to emphasize is that we should remember that '[[' and '[' are all functions that defined in the base package.

Their behaviour is predictable when applying to data.frame or list. But when they were applicable to S4 object, they don't always work in the way you expected. You should read the documents of how they were defined. Don't try to guess by your intuition. This is also a reason of why R is hard to learn.

> fortune(343)
'They' did write documentation that told you that Perl was needed, but 'they'
can't read it for you.
  -- Brian D. Ripley
     R-help (February 2001)

In this post, I would like to introduce how to print a random quotation when every time R is started. It's very easy, just add the following lines to ~/.Rprofile

library("fortunes")
fortune()
2014-12-16-210302_636x506_scrot
Robin Hankin: I'd say that without a tool like R you cannot learn statistics.
David Whiting: I believe Fisher and a few others managed to get by without it.
Peter Dalgaard: But think how far they could have got with R!
  -- Robin Hankin, David Whiting, and Peter Dalgaard (on teaching/learning
     statistics with R)
     R-help (December 2004)

Learn statistics with R is almost unavoidable especially for students in biology.

AND learn R wisdom with fortunes, it can be fun.

2014-11-25-132948_552x414_scrot

写在最后,这是3年前写的博客文,现在有一个叫praise的R包,无比无聊,每次打印一句表扬的话,和fortunes包一样,你可以配合《clifun: 在R里装装逼》,让逼格上升,配合fortunes使用,我就不演示了,因为在clifun包介绍一文中已经有了。

传送门

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存